<template>
  <!-- 上传成功，头部弹框 -->
  <van-notify v-model:show="internalShow" class-name="notify_block">
    <div class="upload_sucess_pop" v-if="internalShow">
      <div class="left_block">
        <img :src="internalImgUrl" />
      </div>
      <div class="center_text">
        <span class="pre">Your AI photo is ready, </span>
        <span class="last">view it now </span>
      </div>
      <img src="@/assets/images/ic_list_next@2x.png" class="last_img" @click="handleClose" />
    </div>
  </van-notify>
</template>

<script setup>
import { useRouter } from "vue-router";
import { ref, watch, inject } from "vue";

const router = useRouter();

const emit = defineEmits(["close"]);
const show = inject("show");
const internalShow = ref(show.value);
watch(show, (newVal) => {
  internalShow.value = newVal;
});

const props = defineProps(["imgUrl", "taskType", "taskNo"]);
const internalImgUrl = ref(props.imgUrl); // 初始值从 props 获取
const taskType = ref(props.taskType); // 初始值从 props 获取
const taskNo = ref(props.taskNo); // 初始值从 props 获取
// 监听父组件传递的 imgUrl 变化
watch(
  () => props.imgUrl,
  (newVal) => {
    internalImgUrl.value = newVal;
  }
);
// 获取 taskType
watch(
  () => props.taskType,
  (newVal) => {
    taskType.value = newVal;
  }
);
// 获取 taskNo
watch(
  () => props.taskNo,
  (newVal) => {
    taskNo.value = newVal;
  }
);

// 关闭
const handleClose = () => {
  internalShow.value = false;
  emit("close");
  if (Number(taskType.value) === 3) {
    router.push({
      path: "/removeCreating",
      query: {
        taskNo: taskNo.value,
        from: "remove",
      },
    });
  } else {
    router.push({
      path: "/poseCreating",
      query: {
        taskNo: taskNo.value,
        from: "pose",
      },
    });
  }
};
</script>

<style scoped lang="less">
.upload_sucess_pop {
  width: 360px;
  height: 80px;
  box-sizing: border-box;
  padding: 16px 12px;
  background: rgba(98, 81, 255, 0.85);
  box-shadow: 0px 4px 12px 0px rgba(0, 0, 0, 0.35);
  border-radius: 8px;
  position: fixed;
  left: 8px;
  top: 2px;
  z-index: 1000;
  display: flex;
  justify-content: left;
  align-items: center;
  .left_block {
    width: 48px;
    height: 48px;
    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  }
  .center_text {
    margin-left: 8px;
    margin-right: 13px;
    .pre {
      font-size: 14px;
      color: #fff;
    }
    .last {
      font-size: 14px;
      color: #ffd900;
    }
  }
  .last_img {
    width: 24px;
    cursor: pointer;
  }
}
</style>
